export default function useMultipartSearch<T extends object>(
  options: LabelValue[],
  params: T
) {
  const activeSearchType = ref<string>(options[0].value)
  const searchKeyword = ref('')

  const placeholder = computed(() => {
    const label = options.find(v => activeSearchType.value === v.value)?.label
    return `请输入${label ?? ''}`
  })

  watch([searchKeyword, activeSearchType], () => {
    options.forEach(item => {
      if (item.value !== activeSearchType.value) {
        Reflect.set(params, item.value, '')
      }
    })
    Reflect.set(params, activeSearchType.value, searchKeyword.value)
  })
  return {
    placeholder,
    activeSearchType,
    searchKeyword
  }
}
